{{ $pag := .Paginator }}
{{ $tps := $pag.TotalPages }}

{{ $begin := sub $pag.PageNumber  4}}
{{ $.Scratch.Set "begin" $begin }}
{{ $end := add $pag.PageNumber  4}}
{{ $.Scratch.Set "end" $end }}

{{ if lt $begin 0}}
  {{ $end := sub $end $begin }}
  {{ $.Scratch.Set "end" $end }}
{{ end}}
{{ $end := $.Scratch.Get "end"}}

{{ $over := sub  $tps $end }}

{{ if lt $over 0}}
  {{ $begin := add $begin $over}}
  {{ $.Scratch.Set "begin" $begin }}
{{ end }}
{{ $begin := $.Scratch.Get "begin"}}
<nav class="pagination">
  {{ if $pag.HasPrev }}
  <a class="extend prev" rel="prev" href="{{ $pag.Prev.URL  }}">
    <i class="fa fa-angle-left"></i>
  </a>
  {{ end }}
  {{ range $p := $pag.Pagers }}
      {{ if and (ge $p.PageNumber $begin) (le $p.PageNumber $end) }}
      {{ if eq $p $pag }}
        <span class="page-number current">{{ $p.PageNumber }}</span>
      {{ else }}
        <a class="page-number" href="{{ $p.URL  }}">{{ $p.PageNumber }}</a>
      {{ end }}
      {{ end }}
  {{ end }}
  {{ if $pag.HasNext }}
  <a class="extend next" rel="next" href="{{ $pag.Next.URL }}">
    <i class="fa fa-angle-right"></i>
  </a>
  {{ end }}
</nav>